import os,sys,getch
from random import *
def a(b):
	print(color('started>%s'%b, 5))
	os.system(b)
	print(color('stopped<%s'%b, 4))

def color(string, num=1) :
	return "\033[1;3%dm%s\033[0m" % (num, string)

def cprint(string) :
	'无颜色的字符^有颜色的字符&无颜色的字符'
	for i in string :
		if i == '^' :
			print('\033[1;31m', end='')
		elif i == '&' :
			print('\033[0m', end='')
		else :
			print(i, end='')
	print('')

help_text='''
^r&unserver\t^s&hell\t\t^l&og (git)
^g&it\t\t^d&iff (git)\t^p&ing
^n&autilus\t^i&nit\t\t^q&uit
^L&og (oneline)\t^S&ync\t\t^G&rep (git)
^f&irefox\t\t^I&nitialize.py\t^c&heckout
^m&erge
'''
cprint(help_text)
while 1:
	print("输入命令：")
	command=getch.getche()
	print('')
	if command=='g':
		a('git add -A')
		a('git commit')
		a('git checkout master')
		a('git pull origin master')
		a('git push origin master')
	elif command == 'c' :
		position = input('position(default=master):')
		if not position :
			position = 'master'
		a('git checkout %s' % position)
	elif command=='G':
		gre = input('输入查询文字（不带引号）')
		a('git grep "%s"'%gre)
	elif command=='r':
		a('python3 mydoc.py')
	elif command=='s':
		cprint('^from mydoc import *&')
		a('python3')
	elif command=='S':
		a('sync')
	elif command=='p':
		a('ping baidu.com -c 4')
		a('ping git.oschina.com -c 4')
	elif command=='d':
		a('git diff')
	elif command=='n':
		a('nautilus . &> /dev/null &')
	elif command=='i':
		a('firefox &> /dev/null &')
		a('nautilus . &> /dev/null &')
		a('gedit README.md &> /dev/null &')
	elif command=='f':
		a('firefox &> /dev/null &')
	elif command=='q':
		break;
	elif command=='l':
		a('git log --graph')
	elif command=='L':
		a('git log --graph --oneline')
	else:
		cprint(help_text)

